﻿#include "ThreeDSurfacePlotSelectorDialog.h"
#include "ui_ThreeDSurfacePlotSelectorDialog.h"
#include "BaseWidget/IdaWidgetHelper.h"
#include "BaseModule/GlobalHelper.h"
#include "BaseModule/IBaseSignal.h"

namespace pst
{
    ThreeDSurfacePlotSelectorDialog::ThreeDSurfacePlotSelectorDialog(QWidget* parent)
        : IdaDialogFrame(parent), ui(new Ui::ThreeDSurfacePlotSelectorDialog())
    {
        ui->setupUi(this);
        this->setWindowTitle(QStringLiteral("三维曲面图"));
        IdaWidgetHelperInstance->setMainButtonStyle(ui->pushButton_accept);
        connect(ui->pushButton_accept, &QPushButton::clicked, this, &ThreeDSurfacePlotSelectorDialog::slot_sendChosen3DSurfaceData);
        connect(ui->pushButton_reject, &QPushButton::clicked, this, [this]()
            { this->close(); });
    }

    ThreeDSurfacePlotSelectorDialog::~ThreeDSurfacePlotSelectorDialog()
    {
        delete ui;
    }

    void ThreeDSurfacePlotSelectorDialog::setFreqencyList(const QList<double>& freqencyList)
    {
        m_freqencyList = freqencyList;
        for (auto i : m_freqencyList)
        {
            ui->comboBox_frequencySelector->addItem(QString::number(i));
        }
        if (!m_freqencyList.isEmpty())
        {
            ui->comboBox_frequencySelector->setCurrentIndex(0);
        }
    }

    QList<double> ThreeDSurfacePlotSelectorDialog::getFreqencyList()
    {
        return m_freqencyList;
    }

    void ThreeDSurfacePlotSelectorDialog::setValueList(const QList<QString>& valueList)
    {
        m_valueGroupNameList = valueList;
        for (auto i : m_valueGroupNameList)
        {
            ui->comboBox_valueSelector->addItem(i);
        }
        if (!m_valueGroupNameList.isEmpty())
        {
            ui->comboBox_valueSelector->setCurrentIndex(0);
        }
    }

    QList<QString> ThreeDSurfacePlotSelectorDialog::getValueList()
    {
        return m_valueGroupNameList;
    }

    void ThreeDSurfacePlotSelectorDialog::setInfomationGraph3DBasical(InfomationGraph3DBasical* info)
    {
        m_info = info;
    }

    InfomationGraph3DBasical ThreeDSurfacePlotSelectorDialog::getInfomationGraph3DBasical()
    {
        return m_info;
    }

    void ThreeDSurfacePlotSelectorDialog::slot_sendChosen3DSurfaceData()
    {
        auto freIndex = ui->comboBox_frequencySelector->currentIndex();
        auto valueIndex = ui->comboBox_valueSelector->currentIndex();

        QStringList geometryFileName = m_info->m_geometryFileName;
        QString geometryFileNameStr = geometryFileName.join(",");

        QStringList _pyCodes{};
        _pyCodes += QString("threedsurfaceplot = PostProcessing.ThreeDSurfacePlot()");
        _pyCodes += QString("threedsurfaceplot.setVariableIndex(%1)").arg(valueIndex);
        _pyCodes += QString("threedsurfaceplot.setFrequency(%1)").arg(freIndex);
        _pyCodes += QString("threedsurfaceplot.setReaderIndex(%1)").arg(m_info->readerIndex);
        _pyCodes += QString("threedsurfaceplot.setFilePath('%1')").arg(m_info->m_filePath);
        _pyCodes += QString("threedsurfaceplot.setName('%1')").arg(m_info->m_name.toUtf8().data());
        _pyCodes += QString("threedsurfaceplot.setGeometryFileName('%1')").arg(geometryFileNameStr.toUtf8().data());
        _pyCodes += QString("threedsurfaceplot.setGraphType(%1)").arg((int)(m_info->m_graphType));
        _pyCodes += QString("threedsurfaceplot.setIsOpenNewWindow(%1)").arg(m_isOpenNewWindow);
        _pyCodes += QString("threedsurfaceplot.create()");
        emit IBaseSignalInstance->signal_execPYCode(_pyCodes, true, false);

        emit signal_sendChosen3DSurfaceData(m_info, freIndex, valueIndex, m_isOpenNewWindow);
        this->close();
    }
} // namespace pst
